package com.xiaoyu.izf.listener;

import com.xiaoyu.izf.event.WithdrawApplyEvent;
import com.xiaoyu.izf.model.UserInfo;
import com.xiaoyu.izf.service.CommissionGetLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 监听提现申请事件to添加提现日志
 */
//@Component
public class ListenWithdrawApplyToAddLog implements ApplicationListener<WithdrawApplyEvent> {

    @Autowired
    private CommissionGetLogService commissionGetLogService;

    @Override
    @Transactional
    public void onApplicationEvent(WithdrawApplyEvent withdrawApplyEvent) {
        if (withdrawApplyEvent.getSource() instanceof UserInfo){
            UserInfo userInfo = (UserInfo) withdrawApplyEvent.getSource();
            commissionGetLogService.add(userInfo.getId(), userInfo.getCommissionPaying());
        }
    }
}
